<?php

// get data
	$d = ($edit) ? $module->groups_get($edit) : false;

// title
	?><h1 class="<?php echo ($add) ? 'add' : 'edit'; ?>"><?php echo ($add) ? $lang->get('add-groups') : $lang->get('edit-groups'); ?></h1><?php

// form
	?>
	<form name="frm" method="post" action="<?php echo $cosa->system('base-url'); ?>/?m=<?php echo $m; ?>&s=<?php echo $s; ?>">
	<input type="hidden" name="<?php echo ($add) ? 'add' : 'edit'; ?>" value="<?php echo ($add) ? '1' : $d['id']; ?>" />
	<ul>
		<li><label for="name"><?php $lang->put('name'); ?></label>
			<input type="text" name="name" value="<?php if($d) echo stripslashes($d['name']); ?>" class="fld" />
		</li>
		<li>
			<ul class="clearfix">
				<li class="fl-l">
					<label for="permissions"><?php $lang->put('permissions-modules'); ?></label><br />
					<?php
					$all_modules = $modules->getInstalledModules();
					$user_modules = ($add) ? array() : $modules->getUserModules($edit);
					
					foreach($all_modules as $k => $v) {
						if($v['type'] == 'hidden') {
							?><input type="hidden" id="permissions_<?php echo stripslashes($v['id']); ?>" name="permissions_<?php echo stripslashes($v['id']); ?>" value="1" /><?php
						}
					}
					echo "\n";
					
					echo '<h3>'.$lang->get('standard-modules').'</h3><ul>'."\n";
					foreach($all_modules as $k => $v) {
						if($v['type'] == 'standard') {
							$checked = (array_key_exists($v['path'], $user_modules)) ? ' checked="checked"' : '';
							?>
							<li><input type="checkbox" id="permissions_<?php echo stripslashes($v['id']); ?>" name="permissions_<?php echo stripslashes($v['id']); ?>" value="1"<?php echo $checked; ?> />
								<abbr title="<?php echo stripslashes($v['description']); ?>"><?php echo stripslashes($v['name']); ?></abbr>
							</li>
							<?php
						}
					}
					echo '</ul><br />'."\n";
					
					echo '<h3>'.$lang->get('system-modules').'</h3><ul>'."\n";
					foreach($all_modules as $k => $v) {
						if($v['type'] == 'system') {
							$checked = (array_key_exists($v['path'], $user_modules)) ? ' checked="checked"' : '';
							?>
							<li><input type="checkbox" id="permissions_<?php echo stripslashes($v['id']); ?>" name="permissions_<?php echo stripslashes($v['id']); ?>" value="1"<?php echo $checked; ?> />
								<abbr title="<?php echo stripslashes($v['description']); ?>"><?php echo stripslashes($v['name']); ?></abbr>
							</li>
							<?php
						}
					}
					echo '</ul><br />'."\n";
					
					?>
				</li>
				<li class="fl-l" style="margin-left:30px">
					<label for="permissions"><?php $lang->put('permissions-languages'); ?></label><br />
					<?php
					$all_languages = $lang->getAllLanguages();
					$user_languages = ($add) ? array() : $user->getLanguages($edit, false);
					
					foreach($all_languages as $k => $domain) {
						?>
						<h3><?php echo stripslashes($domain['name']); ?></h3>
						<ul><?php
							foreach($domain['languages'] as $lk => $language) {
								$checked = (key_exists($language['id'], $user_languages)) ? ' checked="checked"' : '';
								?>
								<li><input type="checkbox" id="lang_permissions_<?php echo stripslashes($language['id']); ?>" name="lang_permissions_<?php echo stripslashes($language['id']); ?>" value="1"<?php echo $checked; ?> />
									<?php echo stripslashes($language['name']); ?>
								</li>
								<?php
							}
							?>
						</ul><br />
						<?php
					}
					
					?>
				</li>
			</ul>
		</li>
		<li class="sbmt">
			<input type="submit" value="<?php $lang->put('submit'); ?>" class="sbmt" />
			<?php if($d) $module->printDelLink($d['id'], false, $lang->get('del-groups')); ?>
		</li>
	</ul>
	</form>

